package com.ahtcm.tcmlearning.utils.generateQustion;

import com.ahtcm.tcmlearning.dataObject.generateQuestion.GenerateQuestion;
import com.ahtcm.tcmlearning.model.Medicine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//中药题目生成器
public class MedicineQuestionGenerateUtil {
    private static String medicineQuestionTitle1 = "的药性为？";//getMedicineProperty   questionId:1
    private static String medicineQuestionTitle2 = "的药效,下列选项正确的是？";//getMedicineEfficiency   questionId:2

    public static List<GenerateQuestion> generate(List<Medicine> optionMedicine, Medicine rightOption) {
        List<GenerateQuestion> list = new ArrayList<>();
        GenerateQuestion question1 = setMedicineValue(optionMedicine, rightOption, medicineQuestionTitle1, 1);
        GenerateQuestion question2 = setMedicineValue(optionMedicine, rightOption, medicineQuestionTitle2, 2);
        list.add(question1);
        list.add(question2);
        Collections.shuffle(list);
        return list;

    }

    private static GenerateQuestion setMedicineValue(List<Medicine> optionMedicine, Medicine rightOption, String medicineQuestionTitle, Integer questionId) {
        medicineQuestionTitle = rightOption.getMedicineName() + medicineQuestionTitle;
        System.out.println(medicineQuestionTitle);
        Collections.shuffle(optionMedicine);
        int rightIndex1 = optionMedicine.indexOf(rightOption);
        GenerateQuestion question = new GenerateQuestion();
        question.setTitle(medicineQuestionTitle);
        question.setAnswerIndex(rightIndex1 + 1);
        if (questionId ==1) {
            if (optionMedicine.size() == 1) question.setChoiceA(optionMedicine.get(0).getMedicineProperty());
            else if (optionMedicine.size() == 2) {
                question.setChoiceA(optionMedicine.get(0).getMedicineProperty());
                question.setChoiceB(optionMedicine.get(1).getMedicineProperty());
            } else if (optionMedicine.size() == 3) {
                question.setChoiceA(optionMedicine.get(0).getMedicineProperty());
                question.setChoiceB(optionMedicine.get(1).getMedicineProperty());
                question.setChoiceC(optionMedicine.get(2).getMedicineProperty());
            } else {
                question.setChoiceA(optionMedicine.get(0).getMedicineProperty());
                question.setChoiceB(optionMedicine.get(1).getMedicineProperty());
                question.setChoiceC(optionMedicine.get(2).getMedicineProperty());
                question.setChoiceD(optionMedicine.get(3).getMedicineProperty());
            }
        }
        if (questionId == 2) {
            if (optionMedicine.size() == 1) question.setChoiceA(optionMedicine.get(0).getMedicineEfficiency());
            else if (optionMedicine.size() == 2) {
                question.setChoiceA(optionMedicine.get(0).getMedicineEfficiency());
                question.setChoiceB(optionMedicine.get(1).getMedicineEfficiency());
            } else if (optionMedicine.size() == 3) {
                question.setChoiceA(optionMedicine.get(0).getMedicineEfficiency());
                question.setChoiceB(optionMedicine.get(1).getMedicineEfficiency());
                question.setChoiceC(optionMedicine.get(2).getMedicineEfficiency());
            } else {
                question.setChoiceA(optionMedicine.get(0).getMedicineEfficiency());
                question.setChoiceB(optionMedicine.get(1).getMedicineEfficiency());
                question.setChoiceC(optionMedicine.get(2).getMedicineEfficiency());
                question.setChoiceD(optionMedicine.get(3).getMedicineEfficiency());
            }
        }
        return question;
    }


}